package utils

import (
	"fmt"
	"log"
	"os/exec"
	"sync"
)

var mu sync.Mutex

func textToAudioFile(text string, output string) (string, error) {
	mu.Lock()
	defer mu.Unlock()
	cmd := fmt.Sprintf("tts --model_path /data/models/zh/model_file.pth --config_path /data/models/zh/config.json --text %s --out_path %s", text, output)
	res, err := exec.Command("/bin/bash", "-c", cmd).CombinedOutput()
	if err != nil {
		return "", err
	}
	cmdResStr := string(res)
	log.Printf("tts cmd exec res : %s", cmdResStr)
	return output, nil
}
